﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>GameScene</title>
<meta name="GENERATOR" content="WinCHM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body><FONT color=#7f0055 size=2><FONT face=Courier><FONT color=#7f0055 size=2>
<P><STRONG>public</STRONG></FONT><FONT color=#000000 size=2> </FONT><FONT 
color=#7f0055 size=2><STRONG>final</STRONG></FONT><FONT color=#000000 size=2> 
</FONT><FONT color=#7f0055 size=2><STRONG>class</STRONG></FONT><FONT 
color=#000000 size=2> GameScene </FONT><FONT color=#7f0055 
size=2><STRONG>extends</STRONG></FONT><FONT color=#000000 size=2> GameCanvas 
</FONT><FONT color=#7f0055 size=2><STRONG>implements</STRONG></FONT><FONT 
size=2><FONT color=#000000> Runnable</FONT></P></FONT></FONT>
<P align=left><FONT face=Courier></FONT>&nbsp;</P><FONT face=Courier><B><FONT color=#7f0055 
size=2>
<P align=left>private</B></FONT><FONT color=#000000 size=2> </FONT><B><FONT 
color=#7f0055 size=2>void</B></FONT><FONT size=2><FONT color=#000000> 
tick(){</FONT></P>
<P align=left><FONT color=#000000></FONT></P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>for</B></FONT><FONT 
size=2>(</FONT><B><FONT color=#7f0055 size=2>int</B></FONT><FONT size=2> 
i=0;i&lt;</FONT><FONT color=#0000c0 size=2>totalLayers</FONT><FONT 
size=2>;i++){</P>
<P align=left>Layer layer=</FONT><FONT color=#0000c0 
size=2>layerManager</FONT><FONT size=2>.getLayerAt(i);</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(layer.isVisible()){</P>
<P align=left>Actor actor=(Actor)layer;</P>
<P align=left></P>
<P align=left>actor.tick();</P>
<P align=left>}</P>
<P align=left>}</P>
<P align=left>applyGameLogic();</P>
<P>}</P></FONT></FONT>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P><FONT 
face=Courier><B><FONT color=#7f0055 size=2>
<P align=left>private</B></FONT><FONT color=#000000 size=2> </FONT><B><FONT 
color=#7f0055 size=2>void</B></FONT><FONT size=2><FONT color=#000000> 
applyGameLogic(){</FONT></P>
<P align=left></FONT><FONT color=#3f7f5f size=2>//normal game 
sequence.</P></FONT><FONT size=2>
<P align=left></FONT><B><FONT color=#7f0055 size=2>long</B></FONT><FONT size=2> 
tickTime=System.<I>currentTimeMillis</I>();;</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(!</FONT><FONT color=#0000c0 size=2>isGameover</FONT><FONT size=2>){</P>
<P align=left></FONT><FONT color=#3f7f5f size=2>//Check if player obtain some 
<U>powerup</U>.</P></FONT><FONT size=2>
<P align=left>Powerup.<I>checkPlayerTank</I>(</FONT><FONT color=#0000c0 
size=2>playerTank</FONT><FONT size=2>);</P>
<P align=left></FONT><FONT color=#3f7f5f size=2>//Spawn enemy tank if 
needed</P></FONT><FONT size=2>
<P align=left></FONT><B><FONT color=#7f0055 size=2>boolean</B></FONT><FONT 
size=2> canSpawnEnemyTank=</FONT><B><FONT color=#7f0055 
size=2>false</B></FONT><FONT size=2>;</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(</FONT><I><FONT color=#0000c0 size=2>enemyTankRemains</I></FONT><FONT 
size=2>-EnemyTank.<I>getVisibleEnemyTanks</I>()&gt;0){</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(EnemyTank.<I>getVisibleEnemyTanks</I>()&lt;10){</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(</FONT><FONT color=#0000c0 size=2>enemySpawnStartTime</FONT><FONT 
size=2>&gt;0){</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(tickTime-</FONT><FONT color=#0000c0 
size=2>enemySpawnStartTime</FONT><FONT size=2>&gt;</FONT><I><FONT color=#0000c0 
size=2>enemySpawnPeriod</I></FONT><FONT size=2>){</P>
<P align=left>canSpawnEnemyTank=</FONT><B><FONT color=#7f0055 
size=2>true</B></FONT><FONT size=2>;</P>
<P align=left>}</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT 
size=2>{</P>
<P align=left>canSpawnEnemyTank=</FONT><B><FONT color=#7f0055 
size=2>true</B></FONT><FONT size=2>;</P>
<P align=left>}</P>
<P align=left>}</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT 
size=2>{</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(EnemyTank.<I>getVisibleEnemyTanks</I>()==0){</P>
<P align=left>ResourceManager.</FONT><I><FONT color=#0000c0 
size=2>gameLevel</I></FONT><FONT size=2>++;</P>
<P align=left>showScoreScreen();</P>
<P align=left>}</P>
<P align=left>}</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(canSpawnEnemyTank){</P>
<P align=left>EnemyTank enemyTank=</FONT><B><FONT color=#7f0055 
size=2>null</B></FONT><FONT size=2>;</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>int</B></FONT><FONT size=2> 
tankSelection=Math.<I>abs</I>(</FONT><I><FONT color=#0000c0 
size=2>rnd</I></FONT><FONT size=2>.nextInt()) % 100;</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(tankSelection&gt;90-ResourceManager.</FONT><I><FONT color=#0000c0 
size=2>gameLevel</I></FONT><FONT size=2>){</P>
<P align=left>enemyTank=EnemyTank.<I>newEnemyTank</I>(EnemyTank.</FONT><I><FONT 
color=#0000c0 size=2>TYPE_HEAVY</I></FONT><FONT size=2>);</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT size=2> 
</FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(tankSelection&gt;75-ResourceManager.</FONT><I><FONT color=#0000c0 
size=2>gameLevel</I></FONT><FONT size=2>){</P>
<P align=left>enemyTank=EnemyTank.<I>newEnemyTank</I>(EnemyTank.</FONT><I><FONT 
color=#0000c0 size=2>TYPE_SMART</I></FONT><FONT size=2>);</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT size=2> 
</FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(tankSelection&gt;55-ResourceManager.</FONT><I><FONT color=#0000c0 
size=2>gameLevel</I></FONT><FONT size=2>){</P>
<P align=left>enemyTank=EnemyTank.<I>newEnemyTank</I>(EnemyTank.</FONT><I><FONT 
color=#0000c0 size=2>TYPE_FAST</I></FONT><FONT size=2>);</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT size=2> 
{</P>
<P align=left>enemyTank=EnemyTank.<I>newEnemyTank</I>(EnemyTank.</FONT><I><FONT 
color=#0000c0 size=2>TYPE_SIMPLE</I></FONT><FONT size=2>);</P>
<P align=left>}</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(enemyTank!=</FONT><B><FONT color=#7f0055 size=2>null</B></FONT><FONT 
size=2>){</P>
<P align=left></P>
<P align=left>tankSelection=Math.<I>abs</I>(</FONT><I><FONT color=#0000c0 
size=2>rnd</I></FONT><FONT size=2>.nextInt()) % 100;</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(tankSelection+ResourceManager.</FONT><I><FONT color=#0000c0 
size=2>gameLevel</I></FONT><FONT size=2>&gt;90){</P>
<P align=left></P>
<P align=left>enemyTank.setHasPrize(</FONT><B><FONT color=#7f0055 
size=2>true</B></FONT><FONT size=2>);</P>
<P align=left>}</P>
<P align=left></FONT><FONT color=#0000c0 size=2>enemySpawnStartTime</FONT><FONT 
size=2>=tickTime;</P>
<P align=left>}</P>
<P align=left></P>
<P align=left>}</P>
<P align=left></FONT><FONT color=#3f7f5f size=2>//Check if player has been 
killed</P></FONT><FONT size=2>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(!</FONT><FONT color=#0000c0 size=2>playerTank</FONT><FONT 
size=2>.isVisible()){</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(</FONT><FONT color=#0000c0 size=2>playerTank</FONT><FONT 
size=2>.getAvaiableLives()&gt;0){</P>
<P align=left></FONT><FONT color=#0000c0 size=2>playerTank</FONT><FONT 
size=2>.initTank();</P>
<P align=left></FONT><FONT color=#0000c0 size=2>playerTank</FONT><FONT 
size=2>.setVisible(</FONT><B><FONT color=#7f0055 size=2>true</B></FONT><FONT 
size=2>);</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT 
size=2>{</P>
<P align=left>gameOver();</P>
<P align=left>}</P>
<P align=left>}</P>
<P align=left></FONT><FONT color=#3f7f5f size=2>//Check if home is been 
<U>destoryed</U>, game over</P></FONT><FONT size=2>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(Powerup.<I>isHomeDestroyed</I>()){</P>
<P align=left>gameOver();</P>
<P align=left>}</P>
<P align=left></FONT><FONT color=#3f7f5f size=2>//put an <U>poweup</U> in the 
battle field</P></FONT><FONT size=2>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>((tickTime-</FONT><FONT color=#0000c0 
size=2>putPowerupStartTime</FONT><FONT size=2>&gt;</FONT><I><FONT color=#0000c0 
size=2>putPowerupPeriod</I></FONT><FONT size=2>) || </FONT><I><FONT 
color=#0000c0 size=2>canPutPowerup</I></FONT><FONT size=2>){</P>
<P align=left>putAnPowerup();</P>
<P align=left>}</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT 
size=2>{</P>
<P align=left></FONT><FONT color=#3f7f5f size=2>//game is over, display game 
over animation.</P></FONT><FONT size=2>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(((tickTime-</FONT><FONT color=#0000c0 
size=2>gameOverStartTime</FONT><FONT size=2>)&lt;</FONT><I><FONT color=#0000c0 
size=2>gameOverPeriod</I></FONT><FONT size=2>) &amp;&amp;</P>
<P align=left></FONT><FONT color=#0000c0 size=2>gameOverStartTime</FONT><FONT 
size=2>&gt;0){</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>int</B></FONT><FONT size=2> 
finalY=(</FONT><I><FONT color=#0000c0 size=2>sceneHeight</I></FONT><FONT 
size=2>-</FONT><I><FONT color=#0000c0 size=2>gameStatus</I></FONT><FONT 
size=2>.getHeight())/2;</P>
<P align=left></FONT><B><FONT color=#7f0055 size=2>if</B></FONT><FONT 
size=2>(</FONT><I><FONT color=#0000c0 size=2>gameStatus</I></FONT><FONT 
size=2>.getY()&gt;finalY){</P>
<P align=left></FONT><I><FONT color=#0000c0 size=2>gameStatus</I></FONT><FONT 
size=2>.setPosition(</FONT><I><FONT color=#0000c0 
size=2>gameStatus</I></FONT><FONT size=2>.getX(),</P>
<P align=left></FONT><I><FONT color=#0000c0 size=2>gameStatus</I></FONT><FONT 
size=2>.getY()-1);</P>
<P align=left>}</P>
<P align=left>}</FONT><B><FONT color=#7f0055 size=2>else</B></FONT><FONT 
size=2>{</P>
<P align=left>showScoreScreen();</P>
<P align=left></FONT><FONT color=#0000c0 size=2>gameOverStartTime</FONT><FONT 
size=2>=0;</P>
<P align=left>}</P>
<P align=left></P>
<P align=left>}</P>
<P>}</P></FONT></FONT>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier></FONT>&nbsp;</P>
<P align=left><FONT face=Courier><STRONG>public</STRONG></FONT></FONT><FONT 
face=Courier><FONT size=2> </FONT><B><FONT color=#7f0055 
size=2>void</B></FONT></FONT><FONT size=2><FONT face=Courier> paint(Graphics 
g){</FONT></P>
<P align=left></FONT><FONT color=#3f7f5f size=2><FONT face=Courier>//Clear the 
background.</FONT></P></FONT><FONT size=2>
<P align=left><FONT face=Courier>clearBackground(g);</FONT></P>
<P align=left></FONT><FONT face=Courier><FONT color=#0000c0 
size=2>layerManager</FONT><FONT size=2>.paint(g,</FONT><FONT color=#0000c0 
size=2>battleFieldX</FONT><FONT size=2>,</FONT><FONT color=#0000c0 
size=2>battleFieldY</FONT></FONT><FONT size=2><FONT face=Courier>);</FONT></P>
<P align=left><FONT face=Courier>drawScoreBar(g);</FONT></P>
<P align=left></FONT><B><FONT color=#7f0055 size=2><FONT 
face=Courier>if</FONT></B></FONT><FONT face=Courier><FONT 
size=2>(</FONT><I><FONT color=#0000c0 size=2>gameStatus</I></FONT></FONT><FONT 
size=2><FONT face=Courier>.isVisible()){</FONT></P>
<P align=left></FONT><I><FONT color=#0000c0 size=2><FONT 
face=Courier>gameStatus</FONT></I></FONT><FONT size=2><FONT 
face=Courier>.paint(g);</FONT></P>
<P align=left><FONT face=Courier>}</FONT></P>
<P align=left><FONT face=Courier></FONT></P>
<P><FONT face=Courier>}</FONT></P></FONT></body>
</html>
